#include<iostream>
#include<algorithm>

using namespace std;
const int N = 110;

struct S {
    int no;
    int grade;

    bool operator<(const S &M) const {
        if (M.grade == grade)
            return no < M.no;
        else return grade < M.grade;
    }
    bool operator>(const S &M) const {
        if (M.grade == grade)
            return no > M.no;
        else return grade > M.grade;
    }
} s[N];

int main() {
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i) {
        cin >> s[i].no >> s[i].grade;
    }
    sort(s, s + n,greater<S>());
    for (int i = 0; i < n; ++i) {
        cout<<s[i].no<<" "<<s[i].grade<<endl;
    }
}